// Created by JIAN HUA
Ext.define('MajorProjectSenchaTouch.controller.FloorPlans', {
    extend: 'Ext.app.Controller',
	requires: [
    'Ext.util.DelayedTask',
	
    ],
	
    config:{
		views: ['FloorPlans.FloorPlans','FloorPlans.levelnine','FloorPlans.leveleight','FloorPlans.levelseven','FloorPlans.levelsix','FloorPlans.levelfive','FloorPlans.levelfour','FloorPlans.levelthree','FloorPlans.leveltwo'],
		refs:{
			navView: 'mainNavView',
			floorplans : '#floorplans',
			floorplansninepage: '#floorplansninepage',
			floorplanseightpage: '#floorplanseightpage',
			floorplanssevenpage: '#floorplanssevenpage',
			floorplanssixpage: '#floorplanssixpage',
			floorplansfivepage: '#floorplansfivepage',
			floorplansfourpage: '#floorplansfourpage',
			floorplansthreepage: '#floorplansthreepage',
			floorplanstwopage: '#floorplanstwopage',
			floorplans9: '#floorplans9',
			floorplans8: '#floorplans8',
			button9: 'button[action=goFloorplansninepage]',
			button8: 'button[action=goFloorplanseightpage]',
			button7: 'button[action=goFloorplanssevenpage]',
			button6: 'button[action=goFloorplanssixpage]',
			button5: 'button[action=goFloorplansfivepage]',
			button4: 'button[action=goFloorplansfourpage]',
			button3: 'button[action=goFloorplansthreepage]',
			button2: 'button[action=goFloorplanstwopage]'
		
		},
		control:{
			button9:{
				tap: 'goFloorplansninepage'
			},
			button8:{
				tap: 'goFloorplanseightpage'
			},
			button7:{
				tap: 'goFloorplanssevenpage'
			},
			button6:{
				tap: 'goFloorplanssixpage'
			},
			button5:{
				tap: 'goFloorplansfivepage'
			},
			button4:{
				tap: 'goFloorplansfourpage'
			},
			button3:{
				tap: 'goFloorplansthreepage'
			},
			button2:{
				tap: 'goFloorplanstwopage'
			}
			
			
		}
	
	},
	goFloorplanstwopage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 2', 'floorplanstwopage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplanstwopage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/7',
			method: 'get',
			scope:this,
			success: function(response) { // Successfully retrieve 
				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
				var s= '<map id="level2" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';
				}
				s+= '</map>';
				MajorProjectSenchaTouch.app.floorplans =s;
				
			var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/7' 
		
			});
		Ext.ComponentQuery.query('#lvl2sdf')[0].setHtml(s, false);
				
			},
			failure: function(response) { // Unable to retrieve 
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	goFloorplansthreepage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 3', 'floorplansthreepage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplansthreepage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/6',
			method: 'get',
			scope:this,
			success: function(response) { // Successfully retrieve 
				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
				// console.log(locations.length);
				var s= '<map id="level3" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';
				}
				s+= '</map>';
		
				MajorProjectSenchaTouch.app.floorplans =s;
				var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/6' 
		
			});
		
				Ext.ComponentQuery.query('#lvl3sdf')[0].setHtml(s, false);
			},
			failure: function(response) { // Unable to retrieve 
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	goFloorplansfourpage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 4', 'floorplansfourpage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplansfourpage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve
			url: 'index.php/floorplans/getFloorplans/5',
			method: 'get',
			scope:this,
			success: function(response) { // Successfully retrieve 
				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
				var s= '<map id="level4" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';
				}
				s+= '</map>';
				
				MajorProjectSenchaTouch.app.floorplans =s;
var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/5' 
		
			});
		
				Ext.ComponentQuery.query('#lvl4sdf')[0].setHtml(s, false);

			
			},
			failure: function(response) { // Unable to retrieve 
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	goFloorplansfivepage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 5', 'floorplansfivepage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplansfivepage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/4',
			method: 'get',
			scope:this,
		
			success: function(response) { // Successfully retrieve 

				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
	
				var s= '<map id="level5" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';
					
				}
				s+= '</map>';
			
				MajorProjectSenchaTouch.app.floorplans =s;

				var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/4' 
		
			});
		
				
				Ext.ComponentQuery.query('#lvl5sdf')[0].setHtml(s, false);

			
			},
			failure: function(response) { // Unable to retrieve 
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	goFloorplanssixpage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 6', 'floorplanssixpage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplanssixpage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/3',
			method: 'get',
			scope:this,

			success: function(response) { // Successfully retrieve 

				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
		
				var s= '<map id="level6" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';
	
				}
				s+= '</map>';

				MajorProjectSenchaTouch.app.floorplans =s;
				var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/3' 
		
			});
		
				Ext.ComponentQuery.query('#lvl6sdf')[0].setHtml(s, false);

			},
			failure: function(response) { // Unable to retrieve 
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	goFloorplanssevenpage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 7', 'floorplanssevenpage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplanssevenpage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/2',
			method: 'get',
			scope:this,
		
			success: function(response) { // Successfully retrieve 

				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
	
				var s= '<map id="level7" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';

				}
				s+= '</map>';
			
				MajorProjectSenchaTouch.app.floorplans =s;
				var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/2' 
		
			});
		
				Ext.ComponentQuery.query('#lvl7sdf')[0].setHtml(s, false);

			
			},
			failure: function(response) { // Unable to retrieve 
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	goFloorplanseightpage: function(){
        var ctrl = this.getApplication().getController('Main');
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Level 8', 'floorplanseightpage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('floorplanseightpage');
        });
        task.delay(1);
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/1',
			method: 'get',
			scope:this,
		
			success: function(response) { // Successfully retrieve

				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
				// console.log(locations.length);
				var s= '<map id="level8" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';
		
				}
				s+= '</map>';
		
				MajorProjectSenchaTouch.app.floorplans =s;
				var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/1' 
		
			});
		

				Ext.ComponentQuery.query('#lvl8sdf')[0].setHtml(s, false);

			},
			failure: function(response) { // Unable to retrieve
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
    },
	lodstoreP: function(){
		
	},
	goFloorplansninepage: function(){
			
			var ctrl = this.getApplication().getController('Main');
				 var previousPage = ctrl.showMask();
			   
				var task = Ext.create('Ext.util.DelayedTask', function(){
					ctrl.pushView('Level 9', 'floorplansninepage');
					ctrl.hideMask(previousPage); 
					
					ctrl.applyNavUrl('floorplansninepage');
				});
				task.delay(1);
		
		
		Ext.Ajax.request({ // Retrieve 
			url: 'index.php/floorplans/getFloorplans/0',
			method: 'get',
			scope:this,
			success: function(response) { // Successfully retrieve 
		
				var string = response.responseText;
				var locations = Ext.decode(string);
				locations = locations.FloorplansInfo;
				var s= '<map id="level9" name="Sencha-Image-Map">';
				for(var i = 0;i<locations.length;i++)
				{
					s += '<area shape="rect" coords="'+locations[i].coords+'" target="staffread" href="'+locations[i].image+'" />';

				}
				s+= '</map>';
		
				MajorProjectSenchaTouch.app.floorplans =s;
			var scope = this;
		
			var floorplanInfoStore = Ext.getStore('floorplanInfo');
		
		
			floorplanInfoStore.removeAll();
		
			floorplanInfoStore.load({
			callback: function(records, operation, success) {
			
			console.log(floorplanInfoStore);

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'floorplans/getFloorplans2/0' 
		
			});
			//this.lodstoreP();
			Ext.ComponentQuery.query('#lvl9sdf')[0].setHtml(s, false);
			},
			failure: function(response) { // Unable to retrieve
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		})
		
	},
	
	 pushView: function(setTitle, setXtype){
        var view = this.getNavView();
        view.push({
            title: setTitle,
            xtype: setXtype
        })
    }
	
 })